/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bean.timer.interfaces;

import com.bean.timer.Timer;
import com.bean.timer.TimerButton;
import java.awt.Color;
import java.awt.Graphics;
import java.io.Serializable;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.event.EventListenerList;

/**
 *
 * @author Lukasz
 */
public abstract class AbstractCompositeTimer extends JPanel implements AbstractTimeView, AbstractTimerControl, AbstractTimerModel, Serializable{

    protected AbstractTimer timer = new Timer();
    protected JButton buttonStartStop = new TimerButton();
    protected JButton buttonReset = new TimerButton();
    
    
    @Override
    public void setFontColor(Color color) {
        Color oldColor = timer.getFontColor();
        timer.setFontColor(color);
        propertyChange(AbstractTimer.PARAM_NAME_FONTCOLOR, oldColor, color);
        
    }

    @Override
    public Color getFontColor() {
        return timer.getFontColor();
    }

    @Override
    public void setBackgroundColor(Color color) {
        Color oldColor = timer.getBackgroundColor();
        timer.setBackgroundColor(color);
        propertyChange(AbstractTimer.PARAM_NAME_BACKGROUNDCOLOR, oldColor, color);
    }

    @Override
    public Color getBackgroundColor() {
        return timer.getBackgroundColor();
    }

    @Override
    public void setFontSize(int size) {
        int oldSize = timer.getFontSize();
        timer.setFontSize(size);
        propertyChange(AbstractTimer.PARAM_NAME_FONTSIZE, oldSize, size);
    }

    @Override
    public int getFontSize() {
        return timer.getFontSize();
    }

    @Override
    public void setHourVisible(boolean visible) {
        boolean oldVisible = timer.isHourVisible();
        timer.setHourVisible(visible);
        propertyChange(AbstractTimer.PARAM_NAME_VISIBLEHOUR, oldVisible, visible);
    }

    @Override
    public boolean isHourVisible() {
        return timer.isHourVisible();
    }

    @Override
    public void setMinuteVisible(boolean visible) {
        boolean oldVisible = timer.isMinuteVisible();
        timer.setMinuteVisible(visible);
        propertyChange(AbstractTimer.PARAM_NAME_VISIBLEMINUTE, oldVisible, visible);
    }

    @Override
    public boolean isMinuteVisible() {
        return timer.isMinuteVisible();
    }

    @Override
    public void setSecondVisible(boolean visible) {
        boolean oldVisible = timer.isSecondVisible();
        timer.setSecondVisible(visible);
        propertyChange(AbstractTimer.PARAM_NAME_VISIBLESECOND, oldVisible, visible);
    }

    @Override
    public boolean isSecondVisible() {
        return timer.isSecondVisible();
    }

    @Override
    public void setMSecondVisible(boolean visible) {
        boolean oldVisible = timer.isMSecondVisible();
        timer.setMSecondVisible(visible);
        propertyChange(AbstractTimer.PARAM_NAME_VISIBLEMSECOND, oldVisible, visible);
    }

    @Override
    public boolean isMSecondVisible() {
        return timer.isMSecondVisible();
    }

    @Override
    public void startTimer() {
        timer.startTimer();
    }

    @Override
    public void stopTimer() {
        timer.stopTimer();
    }

    @Override
    public void resetTimer() {
        timer.resetTimer();
    }

     @Override
    public void setHour(int time){
         int oldTime = timer.getHour();
         timer.setHour(time);
         propertyChange(AbstractTimer.PARAM_NAME_HOUR, oldTime, time);
    }
    @Override
    public int getHour(){
        return timer.getHour();
    }
    
    @Override
    public void setMinute(int time){
         int oldTime = timer.getMinute();
         timer.setMinute(time);
         propertyChange(AbstractTimer.PARAM_NAME_MINUTE, oldTime, time);
    }
    @Override
    public int getMinute(){
        return timer.getMinute();
    }
    
    @Override
    public void setSecond(int time){
         int oldTime = timer.getSecond();
         timer.setSecond(time);
         propertyChange(AbstractTimer.PARAM_NAME_SECOND, oldTime, time);
    }
    @Override
    public int getSecond(){
        return timer.getSecond();
    }
    
    @Override
    public void setMSecond(int time){
         int oldTime = timer.getMSecond();
         timer.setMSecond(time);
         propertyChange(AbstractTimer.PARAM_NAME_MSECOND, oldTime, time);
    }
    @Override
    public int getMSecond(){
        return timer.getMSecond();
    }
    
    @Override
    public long getLimit() {
        return timer.getLimit();
    }

    @Override
    public void setLimit(long limit) {
        long oldLimit = timer.getLimit();
        timer.setLimit(limit);
        propertyChange(AbstractTimer.PARAM_NAME_LIMIT, oldLimit, limit);
    }

    @Override
    public boolean isCountingDown() {
        return timer.isCountingDown();
    }

    @Override
    public void setCountingDown(boolean countingDown) {
        boolean oldCount = timer.isCountingDown();
        timer.setCountingDown(countingDown);
        propertyChange(AbstractTimer.PARAM_NAME_COUNTDOWN, oldCount, countingDown);
    }

    @Override
    public void setWarningTicksCount(int ticks) {
        int oldTick = timer.getWarningTicksCount();
        timer.setWarningTicksCount(ticks);
        propertyChange(AbstractTimer.PARAM_NAME_COUNT, oldTick, ticks);
    }

    @Override
    public int getWarningTicksCount() {
        return timer.getWarningTicksCount();
    }

    @Override
    public void setTickLength(int milisec) {
        int oldMilisec = timer.getTickLength();
        timer.setTickLength(milisec);
        propertyChange(AbstractTimer.PARAM_NAME_TICK_LEN, oldMilisec, milisec);
    }

    @Override
    public int getTickLength() {
        return timer.getTickLength();
    }

    @Override
    public void addTimerListener(TimerListener listener) {
        timer.addTimerListener(listener);
    }

    @Override
    public void removeTimerListener(TimerListener listener) {
        timer.removeTimerListener(listener);
    }

    @Override
    public EventListenerList getTimerListeners() {
        return timer.getTimerListeners();
    }
    
    @Override
    protected abstract void paintComponent(Graphics g);
    
    protected abstract void propertyChange(String property,long oldval, long newval);
    protected abstract void propertyChange(String property,int oldval, int newVal);
    protected abstract void propertyChange(String property,Object oldval, Object newVal);
    protected abstract void propertyChange(String property,boolean oldval, boolean newVal);
}
